<% title "Program Information Tables" %>

<p>
  Download:
  CSV |
  Excel
</p>

<% idFileRedBee = SelectFile.where(:server => "RedBee").first.id%>
<% idSIT = ServiceInformationTable.where(:select_file_id => idFileRedBee)%>
<% idPLT = ProgramLocationTable.where(:select_file_id => idFileRedBee)%>
<% listOfServices = ServiceInformation.where(:service_information_table_id=>idSIT).select(:id).map{|i| i.id }%>
<% listOfServicesAxelS = ServiceInformation.select{|i| i.service_information_table_id != idSIT}.map{|i| i.name}.uniq%>

<table class='tabla'>
	<tr  class='modo1'>
    	<th>Server</th>
    	<th></th>
    	<th>%</th>
    	<th>%</th>
    	<th colspan="2">Average</th>
    	<th colspan="3">With description</th>
    	<th colspan="2">Include</th>
  	</tr>
  <tr  class='modo1'>
    <th>Name</th>
    <th>Items</th>
    <th>Title</th>
    <th>Number of series id.</th>
    <th>Keywords</th>
    <th>Actor list</th>
    <th>Short</th>
    <th>Medium</th>
    <th>Long</th>
    <th>Image</th>
    <th>Dolby</th>
  </tr>
    <tr  class='modo2'>
    	<% 
	     itemWithTitle = 0
	     itemWithShortSynopsis = 0 
	     itemWithMediumSynopsis = 0 
	     itemWithLongSynopsis = 0 
	     totalItems = ProgramInformation.select{|i| i.program_information_table_id==1}.count
	     logger.debug"count items"
		 itemWithTitle = ProgramInformation.select{|i| !i.title.nil? && i.program_information_table_id==1}.count
		 itemWithShortSynopsis 	= ProgramInformation.select{|i| !i.synopses.where(:length=>'short').nil? && i.program_information_table_id==1}.count
		 itemWithMediumSynopsis	= ProgramInformation.select{|i| !i.synopses.where(:length=>'medium').nil? && i.program_information_table_id==1}.count
		 itemWithLongSynopsis	= ProgramInformation.select{|i| !i.synopses.where(:length=>'long').nil? && i.program_information_table_id==1}.count
     	%>
      <td>RedBee</td>>
      <td><%=totalItems %></td>
      <td><%=100*itemWithTitle/totalItems %>%</td>
      <td></td>
      <td></td>
      <td></td>
      <td><%=100*itemWithShortSynopsis/totalItems  %>%</td>
      <td><%=100*itemWithMediumSynopsis/totalItems  %>%</td>
      <td><%=100*itemWithLongSynopsis/totalItems  %>%</td>
      <td></td>
      <td></td>
    </tr>
    
    <tr  class='modo2'>
    	<% 
	     itemWithTitle = 0
	     itemWithShortSynopsis = 0 
	     itemWithMediumSynopsis = 0 
	     itemWithLongSynopsis = 0 
	     totalItems = ProgramInformation.select{|i| i.program_information_table_id!=1}.count
	     logger.debug"count items"
		 itemWithTitle = ProgramInformation.select{|i| !i.title.nil? && i.program_information_table_id!=1}.count
		 itemWithShortSynopsis 	= ProgramInformation.select{|i| !i.synopses.where(:length=>'short').nil? && i.program_information_table_id!=1}.count
		 itemWithMediumSynopsis	= ProgramInformation.select{|i| !i.synopses.where(:length=>'medium').nil? && i.program_information_table_id!=1}.count
		 itemWithLongSynopsis	= ProgramInformation.select{|i| !i.synopses.where(:length=>'long').nil? && i.program_information_table_id!=1}.count
     	%>
      <td>AxelS</td>
      <td><%=totalItems %></td>
      <td><%=100*itemWithTitle/totalItems %>%</td>
      <td></td>
      <td></td>
      <td></td>
      <td><%=100*itemWithShortSynopsis/totalItems  %>%</td>
      <td><%=100*itemWithMediumSynopsis/totalItems  %>%</td>
      <td><%=100*itemWithLongSynopsis/totalItems  %>%</td>
      <td></td>
      <td></td>
    </tr>
  
</table>


